<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>部门管理</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="">
<meta name="description" content="">
{sys:load href="admin/css/bootstrap.min.css,admin/css/materialdesignicons.min.css,admin/css/animate.css,admin/css/style.min.css,admin/js/bootstrap-table/bootstrap-table.min.css,admin/lib/layui/css/layui.css"}
</head>

<body>
<div class="container-fluid p-t-15">

  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-header"><h4>部门列表</h4></div>
        <div class="card-body">

          <div id="toolbar" class="toolbar-btn-action">
             <form class="form-inline" action="lyear_forms_elements.html" method="post" onsubmit="return false;">
                <div class="form-group">
                  <label class="sr-only" for="keyword">关键字</label>
                  <input class="form-control" type="text" id="keyword" name="keyword" placeholder="" autocomplete="off">
                </div>
                <div class="form-group">
                  <button class="btn btn-cyan" type="submit" id="btn-search">检索</button>

                  <button type="button" class="btn btn-primary m-r-5" onclick="openModel('新增部门', '/admin/depart/save')">
                    <span class="mdi mdi-plus" aria-hidden="true"></span>新增
                  </button>

                  <button type="button" class="btn btn-primary m-r-5" onclick="loadSelf()"><span class="mdi mdi-rotate-3d" aria-hidden="true"></span>刷新</button>
                </div>
            </form>
          </div>
          <table id="tb_departments"></table>

        </div>
      </div>
    </div>

</div>

{sys:load href="admin/lib/layui/layui.js,admin/common.js,admin/js/jquery.min.js,admin/js/bootstrap.min.js,admin/js/perfect-scrollbar.min.js,admin/js/bootstrap-table/bootstrap-table.js,admin/js/bootstrap-table/bootstrap-table-zh-CN.min.js"}

<script type="text/html" id="operate">
<a href="javascript:openModel('编辑{{d.name}}', '/admin/depart/save?id={{d.id}}')" class="btn btn-xs btn-default m-r-5" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>
<a href="javascript:del({{d.id}})" class="btn btn-xs btn-default" title="删除"><i class="mdi mdi-window-close"></i></a>
</script>

<script type="text/javascript">
    layui.use(['layer', 'jquery', 'Request','table'], function(){
        var Request = layui.Request , table = layui.table, $ = layui.jquery;

        let dataTableIndex = table.render({
            elem: '#tb_departments'
            ,url:'/admin/depart/datalists'
            ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                  "code": res.state == 'success' ? 0 : -1, //解析接口状态
                  "msg": res.message, //解析提示文本
                  "count": res.data.total, //解析数据长度
                  "data": res.data.rows //解析数据列表
                };
              }
            ,cols: [[
                {field: 'check', type: 'checkbox'}
              ,{field:'id', width:80, title: 'ID', sort: true}
              ,{field:'name', width:120, title: '部门名称'}
              ,{field:'nodes', title: '权限'}
              ,{field:'operate', title: '操作', width: 200, templet: '#operate'}
            ]]
          });

          $("#btn-search").on('click', function(){
              dataTableIndex.reload({
                  where:{keyword: $("#keyword").val()}
              })
          })
    })

    function edit(id)
    {
        openModel('/admin/depart/save?id='+id, '编辑', 800,600 )
    }

    function del(id)
    {
        layui.use(['layer','Request'], function(){
            var layer = layui.layer,request = layui.Request;
            request.get('/admin/depart/delete',{id:id}, function(response){
                layer.msg('成功删除', {time: 1000}, function(){
                    window.location.reload()
                })
            })
        })
    }
</script>
</body>
</html>
